<template>
	<view>
		<my-loading :vshow="loadingshow"></my-loading>
		<u-sticky>
			<view class="subsection">
				<u-subsection :list="subsectionList" :current="current" @change="sectionChange"> </u-subsection>

			
			</view>
		</u-sticky>
		<view class="empty" v-if="erslist == '' && current == 0">
			<u-empty text="暂无记录" mode="list"></u-empty>
		</view>
		<view class="record" v-for="(item, k) in erslist" :key="k" v-if="current == 0">
			<view class="record-content" v-if="item.soure=='product'">
				<view class="content-left">
					<image :src="item.thumbs_text[0]" mode=""></image>
				</view>
				<view class="content-right">
					<view class="right-name">
						{{item.brankname_text}}{{item.btypename_text}}{{ item.code }}
					</view>
					<view class="right-sto">
						{{item.store_text}}
					</view>
					<!-- <view class="right-detail">
						{{item.registrationTime}} | {{item.kilometers}}万公里 | {{item.emission}}
					</view>
					<view class="right-price">
						售价：{{item.price}}万
					</view> -->
					<view class="right-status">
						状态：{{item.suproduct[0].status_text}}
					</view>
				</view>
			</view>
			<view class="record-content" v-else>
				<view class="content-left">
					<image :src="item.thumbs_text[0]" mode=""></image>
				</view>
				<view class="content-right">
					<view class="right-name">
						{{item.brankname_text}}{{item.brankname_text}}{{ item.name }}
					</view>
					<view class="right-sto">
						{{item.store_text}}
					</view>
					<!-- <view class="right-detail">
						{{item.registrationTime}} | {{item.kilometers}}万公里 | {{item.emission}}
					</view>
					<view class="right-price">
						售价：{{item.price}}万
					</view> -->
					<view class="right-status">
						状态：{{item.suproduct[0].status_text}}
					</view>
				</view>
			</view>
			<view class="record-but">
				<view class="but-item" v-if="item.status == '2'">
					<u-button type="primary" :custom-style="customStyle" @click="proDetail(item.id)">编辑</u-button>
				</view>
				<view class="but-item">
					<u-button type="info" :custom-style="customStyle" @click="proInfo({id:item.id,soure:item.soure})">详情</u-button>
				</view>
				<view class="but-item" v-if="item.status == '2'">
					<u-button type="error" :custom-style="customStyle" @click="proOffShelf(item.id)">下架</u-button>
				</view>
				<view class="but-item" v-if="item.status == '4'">
					<u-button type="success" :custom-style="customStyle" @click="proGrounding(item.id)">上架</u-button>
				</view>
				<view class="but-item">
					<u-button type="warning" :custom-style="customStyle" @click="proDel(item.id)">删除</u-button>
				</view>
			</view>
		</view>
		
		<view class="empty" v-if="hirelist == '' && current == 1">
			<u-empty text="暂无记录" mode="list"></u-empty>
		</view>
		<view class="record" v-for="(item, k) in prolist" :key="k" v-if="current == 1">
			<view class="record-content">
				<view class="content-left">
					<image :src="item.thumbs_text[0]" mode=""></image>
				</view>
				<view class="content-right">
					<view class="right-name">
						{{item.brankname_text}}{{item.btypename_text}}{{ item.code }}
					</view>
					<view class="right-sto">
						{{item.store_text}}
					</view>
					<!-- <view class="right-detail">
						{{item.gearbox}} | {{item.emission}} | {{item.fuel}} | {{item.seat}}
					</view>
					<view class="right-price">
						租价：{{item.price}}元
					</view> -->
					<view class="right-status">
						状态：{{item.suproduct[0].status_text}}
					</view>
				</view>
			</view>
			<view class="record-but">
				<view class="but-item" v-if="item.status == '2'">
					<u-button type="primary" @click="gohireDetail(item.id)" :custom-style="customStyle">编辑</u-button>
				</view>
				<view class="but-item">
					<u-button type="info"  @click="proInfo({id:item.id,soure:item.soure})" :custom-style="customStyle">
						详情
					</u-button>
				</view>
				<view class="but-item" v-if="item.status == '2'">
					<u-button type="error" @click="offShelf(item.id)" :custom-style="customStyle">下架</u-button>
				</view>
				<view class="but-item" v-if="item.status == '4'">
					<u-button type="success" @click="grounding(item.id)" :custom-style="customStyle">上架</u-button>
				</view>
				<view class="but-item">
					<u-button type="warning" @click="del(item.id)" :custom-style="customStyle">删除</u-button>
				</view>
			</view>
		</view>
		
		<view class="empty" v-if="userhireOrder == '' && current == 2">
			<u-empty text="暂无订单记录" mode="order"></u-empty>
		</view>
		<view class="record" v-for="(item, k) in userhireOrder" :key="k" v-if="current == 2">
			<view class="record-content" v-if="item.soure=='hire'">
				<view class="content-left">
					<image :src="item.thumbs_text[0]" mode=""></image>
				</view>
				<view class="content-right">
					<view class="right-name">
						{{item.brankname_text}}{{item.btypename_text}}{{ item.code }}
					</view>
					<view class="right-sto">
						{{item.store_text}}
					</view>
					<!-- <view class="right-detail">
						{{item.registrationTime}} | {{item.kilometers}}万公里 | {{item.emission}}
					</view>
					<view class="right-price">
						售价：{{item.price}}万
					</view> -->
					<view class="right-status">
						状态：{{item.suproduct[0].status_text}}
					</view>
				</view>
			</view>
			<view class="record-content" v-else>
				<view class="content-left">
					<image :src="item.thumbs_text[0]" mode=""></image>
				</view>
				<view class="content-right">
					<view class="right-name">
						{{item.brankname_text}}{{item.brankname_text}}{{ item.name }}
					</view>
					<view class="right-sto">
						{{item.store_text}}
					</view>
					<!-- <view class="right-detail">
						{{item.registrationTime}} | {{item.kilometers}}万公里 | {{item.emission}}
					</view>
					<view class="right-price">
						售价：{{item.price}}万
					</view> -->
					<view class="right-status">
						状态：{{item.suproduct[0].status_text}}
					</view>
				</view>
			</view>
			<view class="record-but">
				<view class="but-item" v-if="item.status == '2'">
					<u-button type="primary" :custom-style="customStyle" @click="proDetail(item.id)">编辑</u-button>
				</view>
				<view class="but-item">
					<u-button type="info" :custom-style="customStyle"  @click="proInfo({id:item.id,soure:item.soure})">记录</u-button>
				</view>
				<view class="but-item" v-if="item.status == '2'">
					<u-button type="error" :custom-style="customStyle" @click="proOffShelf(item.id)">下架</u-button>
				</view>
				<view class="but-item" v-if="item.status == '4'">
					<u-button type="success" :custom-style="customStyle" @click="proGrounding(item.id)">上架</u-button>
				</view>
				<view class="but-item">
					<u-button type="warning" :custom-style="customStyle" @click="proDel(item.id)">删除</u-button>
				</view>
			</view>
		</view>
		
		<u-modal 
			v-model="offShelfShow" 
			:mask-close-able="true" 
			show-cancel-button="true" 
			:content="offShelfContent"
			@confirm="offShelfConfirm"
			>
		</u-modal>
		<u-modal
			v-model="proOffShelfShow" 
			:mask-close-able="true" 
			show-cancel-button="true" 
			:content="offShelfContent"
			@confirm="proOffShelfConfirm"
			>
		</u-modal>
		<u-modal
			v-model="groundingShow" 
			:mask-close-able="true" 
			show-cancel-button="true" 
			:content="groundContent"
			@confirm="groundingConfirm"
			>
		</u-modal>
		<u-modal
			v-model="proGroundingShow" 
			:mask-close-able="true" 
			show-cancel-button="true" 
			:content="groundContent"
			@confirm="proGroundingConfirm"
			>
		</u-modal>
		<u-modal
			v-model="delShow" 
			:mask-close-able="true" 
			show-cancel-button="true" 
			:content="delContent"
			@confirm="delConfirm"
			>
		</u-modal>
		<u-modal
			v-model="prodelShow" 
			:mask-close-able="true" 
			show-cancel-button="true" 
			:content="delContent"
			@confirm="prodelConfirm"
			>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				businessinfo: {},
				erslist: [],
				prolist: [],
				userhireOrder: [],
				subsectionList: [
				{
						name: '全部订单'
					},
					{
						name: '手表'
					}, 
					{
						name: '箱包'
					},
					
				],
				current: 0,
				offShelfShow: false,
				proOffShelfShow: false,
				groundingShow: false,
				proGroundingShow: false,
				delShow: false,
				prodelShow: false,
				loadingshow: true,
				offShelfContent: '是否确认下架该商品',
				groundContent: '是否确认上架该商品',
				delContent: '是否确认删除该商品',
				productId: 0,//租车id
				productid: 0,//二手车id
				customStyle: {
					height: '60rpx',
					width: '150rpx'
				},
			}
		},
		onLoad(item) {
			this.businessinfo = this.$u.business.check()
			this.current = item.id
			this.getUserRecord()
			this.getUserRental()
			this.getUserOrderList()
		},
		methods: {
			//编辑二手车按钮
			proDetail(id) {
				uni.navigateTo({
					url: `/pagesC/releaseCar/prodetail?id=`+id
				})
			},
			proInfo(item) {
				uni.$u.route({
					url: `/pagesC/releaseCar/proInfo`,
					params:{
						id:item.id,
						soure:item.soure

					}
				})
			},
			proOffShelf(id) {
				this.proOffShelfShow = true
				this.productid = id
			},
			proGrounding(id) {
				this.proGroundingShow = true
				this.productid = id
			},
			proDel(id) {
				this.prodelShow = true
				this.productid = id
			},
			sectionChange(index) {
				if(index == 0) {
					this.current = 0
					this.getUserRecord()
				}else if(index == 1){
					this.current = 1
					this.getUserRental()
				}else if(index == 2) {
					this.current = 2
					this.getUserOrderList()
				}
			},
			getUserOrderList() {
				this.loadingshow = true;
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/UserOrderList',
					method: 'POST',
					data: {
						busid:this.businessinfo.id
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.userhireOrder = res.data.data
						this.loadingshow = false
					},
				})
			},
			getUserRecord() {
				this.loadingshow = true;
				uni.request({
					url: uni.getStorageSync('URL') + 'home/booking/Cardserver/releaseRecords',
					method: 'GET',
					data: {
						busid:this.businessinfo.id
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.erslist = res.data.data
						this.loadingshow = false
					},
				})
			},
			//获取发布租车列表
			getUserRental() {
				this.loadingshow = true;
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/rentalRecords',
					method: 'GET',
					data: {
						busid: this.businessinfo.id
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						this.prolist = res.data.data
						this.loadingshow = false
					},
				})
			},
			//编辑租车按钮
			gohireDetail(id){
				uni.navigateTo({
					url: `/pagesC/releaseCar/hiredetail?id=`+id
				})
			},
			hireInfo(id) {
				uni.navigateTo({
					url: `/pagesC/releaseCar/hireInfo?id=`+id
				})
			},
			offShelf(id) {
				this.offShelfShow = true
				this.productId = id
			},
			grounding(id) {
				this.groundingShow = true
				this.productId = id
			},
			del(id) {
				this.delShow = true
				this.productId = id
			},
			offShelfConfirm() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/downhire',
					method: 'POST',
					data: {
						busid: this.userId,
						hireid: this.productId
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('商品下架成功')
							this.getUserRental()
						}
					},
				})
			},
			proOffShelfConfirm() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/product/product/downpro',
					method: 'POST',
					data: {
						busid: this.userId,
						proid: this.productid
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('商品下架成功')
							this.getUserRecord()
						}
					},
				})
			},		
			//租车下架按钮
			groundingConfirm() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/uphire',
					method: 'POST',
					data: {
						busid: this.userId,
						hireid: this.productId
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('商品上架成功')
							this.getUserRental()
						}
					},
				})
			},
			//二手车下架按钮
			proGroundingConfirm() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/product/product/upProduct',
					method: 'POST',
					data: {
						busid: this.userId,
						proid: this.productid
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('商品上架成功')
							this.getUserRecord()
						}
					},
				})
			},
			delConfirm() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/hireDel',
					method: 'POST',
					data: {
						hireid: this.productId
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('商品删除成功')
							this.getUserRental()
						}
					},
				})
			},
			prodelConfirm() {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/product/Product/proDel',
					method: 'POST',
					data: {
						proid: this.productid
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('商品删除成功')
							this.getUserRecord()
						}
					},
				})
			},
			confirm(code, hireid) {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/boxconfirm',
					method: 'POST',
					data: {
						code: code,
						hireid: hireid,
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('确认成功')
							this.current = 2
							this.getUserOrderList()
						}
					},
				})
			},
			refuse(code, hireid) {
				uni.request({
					url: uni.getStorageSync('URL') + 'home/hire/hire/boxRefuse',
					method: 'POST',
					data: {
						code: code,
						hireid: hireid,
					},
					header: {
						"X-Requested-With": "XMLHttpRequest"
					},
					dataType: 'json',
					success: (res)=> {
						if(res.statusCode === 200){
							uni.$u.toast('拒绝成功')
							this.current = 2
							this.getUserOrderList()
						}
					},
				})
			},
		},
		filters: {
			formatMendian: function(str) {// 格式化
				const mendian = {
					"1": "拱北店",
					"2": "香洲店",
					"0": "无"
				}
				return mendian[str];
			},
			formatStatus: function(str) {// 格式化
				const status = {
					"1": "待审批",
					"2": "已上架",
					"4": "已下架",
					"0": "全部"
				}
				return status[str];
			},
			formatStatu: function(str) {// 格式化
				const statu = {
					"1": "已超时或已拒绝",
					"2": "已确认",
					"0": "待确认"
				}
				return statu[str];
			},
			formatOrder: function(str) {// 格式化
				const status = {
					"10": "订单已被接单",
					"9": "订单已取消",
					"8": "退款已拒绝",
					"7": "订单已退款",
					"6": "订单待退款",
					"5": "订单已评价",
					"4": "订单已完成",
					"3": "订单进行中",
					"2": "订单已支付,等待处理中",
					"1": "订单未支付",
					"0": ""
				}
				return status[str];
			},
		}
	}
</script>

<style lang="scss" scoped>
page{
	background-color: #f1f1f1;
}
.empty {
	margin-top: 100rpx;
}
.record {
	width: 100%;
	height: 175px;
	background-color: white;
	margin-top: 10px;
	.record-content {
		display: flex;
		border-bottom: 1px solid #efefef;
		.content-left {
			width: 40%;
			padding: 10px;
			height: 120px;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.content-right {
			padding: 10px;
			width: 60%;
			.right-name {
				font-size: 17px;
				font-weight: bold;
				color: black;
			}
			.right-sto, .right-detail {
				font-size: 0.9rem;
				color: #999999;
				margin-top: 20rpx;
			}
			.right-price, .right-status {
				font-size: 20px;
				color: red;
				margin-top: 30rpx;
			}
		}
	}
	.record-but {
		display: flex;
		justify-content: flex-end;
		.but-item {
			margin: 10px 15px 0 0;
		}
	}
}
.infoCard {
	width: 90%;
	margin: 20rpx auto;
	background-color: #fff;
	border-radius: 20rpx;
	.info-data {
		padding: 15rpx;
		border-bottom: 1rpx solid #eee;
		.data-status {
			display: flex;
			.status-left {
				width: 50%;
				margin-left: 20rpx;
			}
			.status-rigth {
				width: 50%;
				text-align: right;
				margin-right: 20rpx;
			}
		}
		.data-orderid, .data-time, .data-storm, .data-orderstatus {
			text-align: left;
			margin-left: 20rpx;
			margin-top: 15rpx;
			font-size: 1.1rem;
		}
	}
	.info-but {
		height: 70rpx;
		margin-top: 10rpx;
		display: flex;
		justify-content: space-around;
	}
}
	
</style>

